package edu.pku.sei.modeler.uml.actions;

import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import edu.pku.sei.gefcommon.common.resourceManager.ResourceGroupManager;
import edu.pku.sei.modeler.edit.parts.AbstractNodeEditPart;
import edu.pku.sei.modeler.model.structure.MetaNode;

public class ChangeLineColorAction extends Action {
	private List<AbstractNodeEditPart> editparts;
	protected Shell shell = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			.getActivePage().getWorkbenchWindow().getShell(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.SYSTEM_MODAL);
	
	public ChangeLineColorAction(List list) {
		super();
		this.setText("Change Line Color");
		this.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
				getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
		editparts = list;
	}

	public void run(){
		ColorDialog cd = new ColorDialog(shell);
		cd.setText("Change Line Color");
		cd.setRGB(new RGB(255, 255, 255));
		RGB color = cd.open();
		if (color == null){
			return;
		}
		Iterator<AbstractNodeEditPart> it = editparts.iterator();
		while(it.hasNext()) {
			MetaNode node = (MetaNode) it.next().getModel();
			node.setLineColor(ResourceGroupManager.getSWTColor(color.red, color.green, color.blue));
		}
	}
}
